python loop list backwards

26

for item in my_list[::-1]:
    print item
    
for i in reversed(xrange(101)):
    print i,
# create a list of prime numbers
prime_numbers = [2, 3, 5, 7]

# reverse the order of list elements
prime_numbers.reverse()


print('Reversed List:', prime_numbers)

# Output: Reversed List: [7, 5, 3, 2]

Comments

Submit
0 Comments